<%@ page language="java" contentType="text/html; charset=UTF-8" 
import="java.util.*,com.jspsmart.upload.*,java.text.SimpleDateFormat,javax.servlet.ServletConfig;"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><%
	 	String FileName = null;
	 	String sPath = "/resources/photos";
	 	SmartUpload mySmartUpload = new SmartUpload();
		mySmartUpload.initialize(config, request, response);
		mySmartUpload.setMaxFileSize(2048 * 1024);
		mySmartUpload.setAllowedFilesList("jpg,gif,png,jpeg,bmp,txt,doc,pdf");
		try {
			mySmartUpload.upload();//上传
			int count = mySmartUpload.save("/resources/photos",1);
			//将图片直接保存在"/resources/photos"路径下，不改变其原名；
			//System.out.println(count+" 个文件上传成功！");
			ArrayList photolist=new ArrayList();
			for(int i = 0;i<mySmartUpload.getFiles().getCount();i++)
			{
				File myFile = mySmartUpload.getFiles().getFile(i);
				if (!myFile.isMissing()) {
					Date currTime = new Date();
					SimpleDateFormat formatter2 = new SimpleDateFormat(
							"yyyyMMddhhmmssSS", Locale.US);
					FileName = new String((formatter2.format(currTime))
							.getBytes("iso-8859-1"));
					String ext = myFile.getFileExt();
					FileName = FileName +i+ "." + ext;
					System.out.println(sPath);
					System.out.println(FileName);
					System.out.println(sPath + "/" + FileName);
					//将文件另存为，已改名
					myFile.saveAs(sPath + "/" + FileName,mySmartUpload.SAVE_VIRTUAL);
					photolist.add(FileName);
				}else{	
					continue ;//如果文件不存在，则继续
				}
			}
			session.setAttribute("photolist", photolist);
			//System.out.println(photolist);
			//Picurl="+ FileName + "
			//getServletConfig().getServletContext().getRequestDispatcher("/bluemsun/pages/admin/pic/pic_add_chuli.jsp").forward(request,response);
			response.sendRedirect("/101/pages/admin/picnews/pic_add_update.jsp");
		} catch (Exception e) {
			e.printStackTrace();
			String errors="<li>文件下载失败：请检查选择的文件是否存在？</li>";
      	    request.setAttribute("errors",errors);
		}
	 %>

</body>
</html>